#ifndef CALC_H_
#define CALC_H_
#include "SFcalcError.h"
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

class calc
{
public:
	calc();
	calc(const string&);
	void input(istream &ins = cin);
	void input(const string&);
	void runIt();
	void output(ostream &ous = cout);
	void output(string &);
	void output(long double &);
	void outHistory(ostream &ous = cout);
	void outHistory(string &);
	void outEveLog(ostream &ous = cout);
	void outEveLog(string &);
	bool setMap(string,string);
	void delMap(string);
	void outMapToFile(string fileName="sfcalc.dat");
	void inMapFromFile(string fileName = "sfcalc.dat", bool cover = false);

private:
	class mapStruct {
	public:
		char sure[8];
		char key[64];
		char value[64];
	};
	string sourceStr;
	string convstr;
	string history;
	string eventLog;
	long double result_d;
	map<string, string> maprep;
	map<pair<char, char>, bool> errgrp;
	vector<string> repsort;
	vector<string> shortSym;
	map<string, int> argNum;

	bool judgeCmd();
	void doit();

	void setRepMap();


	void check();
	bool bracket_match();
	void uptolow();
	void convent();
	void addjc();
	bool checkSym();
	bool char_match();
	void startCalc();
	bool arg_num_match();
	int getArgc(int,string,vector<string>&,int &);
	vector<string> op;
	map<char, int> opIndex;
	string singleCalc(string);
	string doubleCalc(string);
	string calcMode(string, vector<string>);
	long double getLast(vector<long double>&,int t=1);
	void delBracket(string&);

	long double jec(int t);

	void outHis();
	void outLog(string);
	void refreshMap();
};


#endif